package com.hz.framework.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/***
 * 编码过滤器
 * */
public class SetCharacterEncoding implements Filter {
	private String attribute = null;

	public void destroy() {
		this.attribute = null;
	}

	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
		request.setCharacterEncoding(this.attribute);
//		HttpServletRequest httprequest = (HttpServletRequest)request;//   
//		HttpServletResponse httpresponse = (HttpServletResponse)response; 
//		   
//		String currentURL = httprequest.getRequestURI();   
//		   
//		String targetURL = currentURL.substring(currentURL.indexOf("/", 1), currentURL.length());     
		//HttpSession session = httprequest.getSession(false);   
//		System.out.println("++++++++++++++++++++++++"+this.attribute);
		/*if (!"/login.jsp".equals(targetURL)&&!currentURL.endsWith("/login.do")) {
			if (session==null || session.getAttribute("loginname")==null) {   
		     httpresponse.sendRedirect(httprequest.getContextPath() + "/login.jsp");  
		     return;   
		    }   
		   }  */
		chain.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		this.attribute = filterConfig.getInitParameter("encoding");
	}

}
